//
//  ServiceViewController.m
//  Project two framework
//
//  Created by 张峥 on 16/7/21.
//  Copyright © 2016年 张峥. All rights reserved.
//

#import "ServiceViewController.h"
#import "policyConsultView.h"
#import "ComboView.h"
#import "OptionalView.h"
#import "ZPZNetRequest+MealsList.h"
#import "ZPZNetRequest.h"
#import "LStringUtils.h"
#import "AFNetworking.h"
//#import "VideoViewController.h"


@interface ServiceViewController (){
    UIButton *_headLine;
    UIButton *_keyword;

}

@property(nonatomic,strong)policyConsultView    *policyConsultView;
@property(nonatomic,strong)ComboView            *comboView;
@property(nonatomic,strong)OptionalView         *optionalView;


/**分段控制器*/
@property(nonatomic,strong)UISegmentedControl *segmented;
/**阴影*/
@property(nonatomic,strong)UIImageView *shadow;

@property(nonatomic,strong)NSArray *imageArray;
@property(nonatomic,strong)NSArray *imageArray1;
/**右上角搜索*/
@property(nonatomic,strong)UIView *grabbleView;
@property(nonatomic,strong)UIButton *grabbleBtn;
@property(nonatomic,strong)UITextField *grabbleField;
@property(nonatomic,strong)UIButton *grabbleBtn1;

@property(nonatomic,strong)UIView *clickGrabbleBtnView;

/**右上角视频链接*/
@property(nonatomic,strong)UIButton *interlinkageBtn;

@end

@implementation ServiceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor yellowColor];
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"背景.png"]];
 
    [self.view addSubview:self.segmented];
    
    [self clickSegmentde:self.segmented];
    [self shadow];

    [self grabbleView];
  
    [self grabbleBtn1];
    [self grabbleField];
    [self grabbleBtn];
    
    [self interlinkageBtn];
    
    
}

-(void)clickSegmentde:(UISegmentedControl *)sender{

    if (sender.selectedSegmentIndex == 0) {
        

        [self.view addSubview:self.policyConsultView];
//        [self initializeDataSource];
        [self.view addSubview:self.grabbleView];
        _grabbleView.hidden = NO;
//        [_interlinkageBtn removeFromSuperview];
        [_optionalView removeFromSuperview];
        [_comboView removeFromSuperview];
    }else if (sender.selectedSegmentIndex == 1){
        [self.view addSubview:self.comboView];
        [self.view addSubview:_interlinkageBtn];
        _interlinkageBtn.hidden = NO;
        _grabbleView.hidden = YES;
//        [_grabbleView removeFromSuperview];
        [_optionalView removeFromSuperview];
        [_policyConsultView removeFromSuperview];
    
    }else if (sender.selectedSegmentIndex == 2){
        [self.view addSubview:self.optionalView];
        [self.view addSubview:_interlinkageBtn];
         _interlinkageBtn.hidden = NO;
        _grabbleView.hidden = YES;
//        [_grabbleView removeFromSuperview];
        [_policyConsultView removeFromSuperview];
        [_comboView removeFromSuperview];
    
    }

}
#pragma mark --点击事件
-(void)clickGrabbleBtn:(UIButton *)sender{
    if (self.clickGrabbleBtnView.hidden) {
        [UIView animateWithDuration:0.5 animations:^{
            [self clickGrabbleBtnView];
             self.clickGrabbleBtnView.hidden = YES;
        }];
       
    }else{
        [UIView animateWithDuration:0.5 animations:^{
//            [self clickGrabbleBtnView];
            self.clickGrabbleBtnView.hidden = NO;
        }];
        
    }
 
    
    
}

//按照标题搜索
-(void)clickHeadline{
    _headLine.backgroundColor = [UIColor colorWithRed:214/250.0 green:214/250.0 blue:214/250.0 alpha:1];
    self.clickGrabbleBtnView.hidden = YES;
    
}

//按照关键字搜索
-(void)clickKeyword{
    _keyword.backgroundColor = [UIColor colorWithRed:214/250.0 green:214/250.0 blue:214/250.0 alpha:1];
    self.clickGrabbleBtnView.hidden = YES;
}

//视频链接按钮
-(void)clickInterlinkageBtn:(UIButton *)sender{
//    VideoViewController *video = [VideoViewController new];
//    [self presentViewController:video animated:YES completion:nil];
    
    
}

-(ComboView *)comboView
{
    if (_comboView == nil) {
        _comboView = [[ComboView alloc]initWithFrame:CGRectMake(70, 160, SCREEN_WIDTH -70, SCREEN_HEIGHT)];
    }
    return _comboView;
}

-(policyConsultView *)policyConsultView
{
    if (_policyConsultView == nil) {
        _policyConsultView = [[policyConsultView alloc]initWithFrame:CGRectMake(45, 0, 825, 480)];
    }
    return _policyConsultView;
}
-(OptionalView *)optionalView
{
    if (_optionalView == nil) {
        _optionalView = [[OptionalView alloc]initWithFrame:CGRectMake(70, 160, SCREEN_WIDTH -70, SCREEN_HEIGHT)];
    }
    return _optionalView;
}

-(UIImageView *)shadow
{
    if (_shadow == nil) {
        _shadow = [[UIImageView alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2/2, 65, 390, 12)];
        _shadow.image = [UIImage imageNamed:@"shadow_08.png"];
        [self.view addSubview:_shadow];
    }
    return _shadow;
}

-(UISegmentedControl *)segmented
{
    if (_segmented == nil) {
            UIImage * image1=[UIImage imageNamed:@"a_07.png"];
            UIImage * image2=[UIImage imageNamed:@"b_08.png"];
            UIImage * image3=[UIImage imageNamed:@"c_09.png"];
        
        _imageArray = [[NSArray alloc]initWithObjects:image1,image2,image3, nil];
        _segmented = [[UISegmentedControl alloc]initWithItems:@[@"",@"",@""]];
        //必须把图片等渲染方式改变了，不然会不起作用
        [_segmented setImage:[image1 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forSegmentAtIndex:0];
        [_segmented setImage:[image2 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forSegmentAtIndex:1];
        [_segmented setImage:[image3 imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forSegmentAtIndex:2];
        _segmented.frame = CGRectMake(SCREEN_WIDTH/2/2, 25, 390, 40);

        
        _segmented.tintColor = [UIColor clearColor];
        //默认第一个
        _segmented.selectedSegmentIndex = 0;
        _segmented.layer.cornerRadius = 20;
        _segmented.clipsToBounds = YES;
        [_segmented addTarget:self action:@selector(clickSegmentde:) forControlEvents:UIControlEventValueChanged];
    }
    return _segmented;
}

-(UIView *)grabbleView
{
    if (_grabbleView == nil) {
        _grabbleView = [[UIView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width / 2 + 150, 25, 240, 40)];
        _grabbleView.backgroundColor = [UIColor clearColor];
        _grabbleView.hidden = YES;
        [self.view addSubview:_grabbleView];
        
    }
    return _grabbleView;

}

-(UIButton *)grabbleBtn
{
    if (_grabbleBtn == nil) {
        _grabbleBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _grabbleBtn.frame = CGRectMake(0, 0, 56, 40);
        [_grabbleBtn setImage:[UIImage imageNamed:@"choose_01"] forState:UIControlStateNormal];
        [_grabbleBtn addTarget:self action:@selector(clickGrabbleBtn:) forControlEvents:UIControlEventTouchUpInside];
        _grabbleBtn.userInteractionEnabled = YES;
        [_grabbleBtn1 addSubview:_grabbleBtn];
        
        
    }
    return _grabbleBtn;
}

-(UITextField *)grabbleField
{
    if (_grabbleField == nil) {
        _grabbleField = [[UITextField alloc]initWithFrame:CGRectMake(60, 0, 180, 40)];
        _grabbleField.backgroundColor = [UIColor clearColor];
        _grabbleField.textAlignment = NSTextAlignmentLeft;
        _grabbleField.clearButtonMode = UITextFieldViewModeWhileEditing;
        [_grabbleBtn1 addSubview:_grabbleField];
        
    }
    return _grabbleField;
}


-(UIButton *)grabbleBtn1{
    if (_grabbleBtn1 == nil) {
        _grabbleBtn1 = [UIButton buttonWithType:UIButtonTypeCustom];
        _grabbleBtn1.frame = CGRectMake(0, 0, 240, 40);
        [_grabbleBtn1 setImage:[UIImage imageNamed:@"搜索框_11.png"] forState:UIControlStateNormal];
//        _grabbleBtn1.backgroundColor = [UIColor redColor];
        _grabbleBtn1.userInteractionEnabled = YES;
        [_grabbleView addSubview:_grabbleBtn1];
    }
    return _grabbleBtn1;
}


-(UIButton *)interlinkageBtn
{
    if (_interlinkageBtn == nil) {
        _interlinkageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _interlinkageBtn.frame = CGRectMake(700, 25, 50, 40);
        [_interlinkageBtn setImage:[UIImage imageNamed:@"视频图标_05"] forState:UIControlStateNormal];
        _interlinkageBtn.hidden = YES;
        
        [_interlinkageBtn addTarget:self action:@selector(clickInterlinkageBtn:) forControlEvents:UIControlEventTouchUpInside];
        
        [self.view addSubview:_interlinkageBtn];
    }
    return _interlinkageBtn;

}

-(UIView *)clickGrabbleBtnView
{
    if (_clickGrabbleBtnView == nil) {
        _clickGrabbleBtnView = [[UIView alloc]initWithFrame:CGRectMake(self.view.bounds.size.width / 2 + 200, 65, 240, 160)];
        _clickGrabbleBtnView.backgroundColor = [UIColor colorWithRed:214/250.0 green:214/250.0 blue:214/250.0 alpha:1];
        _clickGrabbleBtnView.alpha = 0.6;
        
        UIButton *headline = [UIButton buttonWithType:UIButtonTypeCustom];
        headline.frame = CGRectMake(0, 0, 240, 30);
        headline.backgroundColor = [UIColor whiteColor];
        [headline setTitle:@"标题" forState:UIControlStateNormal];
        [headline setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        headline.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _headLine = headline;
        [headline addTarget:self action:@selector(clickHeadline) forControlEvents:UIControlEventTouchUpInside];
        [_clickGrabbleBtnView addSubview:headline];
        
        UIButton *keyword = [UIButton buttonWithType:UIButtonTypeCustom];
        keyword.frame = CGRectMake(0, 30, 240, 30);
        keyword.backgroundColor = [UIColor whiteColor];
        [keyword setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        //文字居左
        keyword.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _keyword = keyword;
        [keyword setTitle:@"关键字" forState:UIControlStateNormal];
        [keyword addTarget:self action:@selector(clickKeyword) forControlEvents:UIControlEventTouchUpInside];
        
        [_clickGrabbleBtnView addSubview:keyword];
        
        [self.view addSubview:_clickGrabbleBtnView];
    }
    return _clickGrabbleBtnView;
}




@end
